#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>      
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include "lcd.h"
#include "word.h"

unsigned char numbers[10][25][16/8]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x3F,0xC0,
0x7B,0xC0,0x71,0xE0,0xF1,0xE0,0xF0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xF1,0xE0,
0xF1,0xC0,0x7B,0xC0,0x7F,0x80,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x1F,0x00,
0x7F,0x00,0x7F,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,
0x0F,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x7F,0xC0,
0x73,0xC0,0x61,0xC0,0x01,0xC0,0x01,0xC0,0x03,0x80,0x07,0x00,0x1E,0x00,0x38,0x00,
0x70,0x00,0x70,0x00,0xFF,0xE0,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x7F,0x80,
0x73,0xC0,0x01,0xC0,0x03,0xC0,0x03,0x80,0x3F,0x00,0x3F,0x80,0x03,0xC0,0x01,0xC0,
0x01,0xC0,0x63,0xC0,0x7F,0x80,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x07,0x80,
0x0F,0x80,0x0F,0x80,0x1F,0x80,0x3F,0x80,0x3B,0x80,0x73,0x80,0xE3,0x80,0xFF,0xE0,
0xFF,0xE0,0x03,0x80,0x03,0x80,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xC0,0x7F,0xC0,
0x78,0x00,0x70,0x00,0x70,0x00,0x7F,0x00,0x7F,0x80,0x03,0xC0,0x01,0xC0,0x01,0xC0,
0x01,0xC0,0x63,0xC0,0x7F,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x80,0x1F,0xC0,
0x3C,0xC0,0x78,0x00,0x70,0x00,0x7F,0x80,0xFF,0xC0,0xF9,0xE0,0xF1,0xE0,0xF0,0xE0,
0x71,0xE0,0x79,0xC0,0x3F,0xC0,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xE0,0xFF,0xE0,
0x01,0xC0,0x03,0xC0,0x03,0x80,0x07,0x00,0x07,0x00,0x0F,0x00,0x0E,0x00,0x1E,0x00,
0x1C,0x00,0x1C,0x00,0x3C,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x7F,0xC0,
0x7B,0xC0,0x71,0xC0,0x71,0xC0,0x3B,0x80,0x1F,0x00,0x7F,0xC0,0x71,0xE0,0xF0,0xE0,
0xF0,0xE0,0xF1,0xE0,0x7F,0xC0,0x3F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x7F,0x80,
0x73,0xC0,0xF1,0xC0,0xE1,0xE0,0xF1,0xE0,0xF3,0xE0,0x7F,0xE0,0x3F,0xE0,0x01,0xC0,
0x01,0xC0,0x67,0xC0,0x7F,0x80,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,
};

void show_word(int x0, int y0, int w, int h, unsigned char word[][w/8], int color)
{
    int i, j, k;
    for( i=0; i<h; i++ )
    {
        for( j=0; j<w/8; j++ )
        {
            //解析 word[i][j] 的8个bits位，为1就显示颜色，为0就不显示 
            for( k=7; k>=0; k-- )
            {
                if( word[i][j] & (1<<k) )
                {
                    //画点
                     display_point( j*8+(7-k)+x0 , i+y0 , color );
                }
            }
        }
    }
}

void show_number(int x0,int y0,int num,int color)
{
    if(num>=0)
    {
    while(num)
    {
        show_word(x0,y0,16,31,numbers[num%10],color);
        num/=10;
        x0-=20;
    }
    }


}
//60秒倒计时函数
void count_down(int x0,int y0,int color)
{
    int i;
    for(i=60;i>=0;i--)
    {
        show_a_rectangle(x0-20,y0,36,31,0xFFFFFF);
        show_number(x0,y0,i,color);
        sleep(1);
    }
}